package cate.game.play.skill.brother;

import cate.common.table.d.GD;
import cate.common.table.d.GDPos;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.Iterator;
import java.util.List;

@NoteClass("根据主技能目标相对位置的人数来释放")
public class RelativeNumBS extends BrotherSkillSelector {

	@NoteField("相对位置")
	private byte relative;

	@NoteField("检测操作")
	private byte compare;

	@NoteField("人数")
	private int num;

	//相对位置=1&检测操作=4&人数=3
	@Override
	protected void parseArgs(PlayCfgArgs args) {
		relative = args.getByte("相对位置", GDPos.RelativeType.SAME_ROW);
		compare = args.getByte("检测操作", GD.Compare.EQ);
		num = args.getInt("人数", 1);
	}

	@Override
	public boolean check(SkillActionCtx action) {
		int totalNum = 0;
		List<Fighter> parantTargets = action.getTargets();
		if (parantTargets.isEmpty()) {
			return false;
		}
		List<Fighter> aliveFighters = parantTargets.get(0).getFightTeam().getFightersAlive();
		for (Fighter parantTarget : parantTargets) {
			Iterator<Fighter> it = aliveFighters.iterator();
			while (it.hasNext()) {
				Fighter aliveFighter = it.next();
				if (parantTarget.getPid() == aliveFighter.getPid()) {
					continue;
				}
				if (GDPos.relativeCheck(relative, parantTarget.getPos(), aliveFighter.getPos())) {
					it.remove();
					totalNum++;
				}
			}
		}
		return GD.Compare.calc(compare, totalNum, num);
	}
}
